package com.wandar.gc.util;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 */

/**
 * @author huangxm
 * 
 */
public class StringUtil {
	
	public static String getPropertyName(String columnName) {
		StringBuilder sb = new StringBuilder();
		boolean match = false;
		for (int i = 0; i < columnName.length(); i++) {
			char ch = columnName.charAt(i);
			if (match && ch >= 97 && ch <= 122)
				ch -= 32;
			if (ch != '_') {
				match = false;
				sb.append(ch);
			} else {
				match = true;
			}
		}
		return sb.toString();
	}
	
	public static String firstLetterToUpper(String str) {
		char[] array = str.toCharArray();
		Pattern pattern = Pattern.compile("[a-z|A-Z]");
		Matcher matcher = pattern.matcher(String.valueOf(array[0]));
		if (matcher.find()) {
			array[0] -= 32;
		}
		
		return String.valueOf(array);
	}
	
	public static String firstLetterToLowerCase(String str) {
		char[] array = str.toCharArray();
		Pattern pattern = Pattern.compile("[a-z|A-Z]");
		Matcher matcher = pattern.matcher(String.valueOf(array[0]));
		if (matcher.find()) {
			array[0] += 32;
		}
		
		return String.valueOf(array);
	}
	
	public static void mkdir(String path) {
		
		if (StringUtils.isEmpty(path)) {
			throw new NullPointerException("path Files can't be empty");
		}
		File dir = new File(path);
		if (!dir.exists()) {
			dir.mkdirs();
		}
	}
	
	/**
	 * 获取下划线首字母转换为大写
	 * 比如传入 hello_word 获取到 HW
	 * @author huangxm
	 * 2014年12月2日 下午10:33:36
	 * @param str
	 * @return
	 */
	public static String getfirstCharacter(String str) { 
		StringBuffer sb = new StringBuffer();
		if(StringUtils.isNotBlank(str)){
			char first = str.charAt(0);
			//转换为大写
//			first = (char) (first - 32);
			sb.append(first);
		
			int count = str.indexOf("_");
			while (count != 0) {
				int num = str.indexOf("_", count);
				count = num + 1;
				if (num != -1) {
					char ss = str.charAt(count);
					//转换为大写
//					char ia = (char) (ss - 32);
					sb.append(ss);
				}
			}
		}
		return sb.toString();
	}
	
	public static void main(String args[]) {
		
		System.out.println(StringUtil.getPropertyName("java_ok_asda_ss_111"));
		System.out.println(StringUtil.firstLetterToLowerCase("Adasdas"));
		
	}
	
}
